#include<bits/stdc++.h>
using namespace std;
int i,j,n,T,a[25],ans=0;
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--)
    {
        ans=0; cin>>n;
        for(i=1;i<=n;i++) cin>>a[i];
        for(i=0;i<(1<<n);i++)
        {
            int st=i,rst=-1,bst=-1,cnt=0;
            for(j=1;j<=n;j++)
            {
                if(st%2==0)
                {
                    if(bst==a[j])
                        cnt+=a[j];
                    else bst=a[j];
                }
                if(st%2==1)
                {
                    if(rst==a[j])
                        cnt+=a[j];
                    else rst=a[j];
                }
                st=st/2;
            }
            ans=max(ans,cnt);
        }
        cout<<ans<<endl;
    }
    return 0;
}
